package com.hzeport.bgs22emduty.outbound.db;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzeport.bgs22emduty.dto.ScreenMessageReadDTO;
import com.hzeport.bgs22emduty.entity.DutyScheduleSetCustomRecord;
import com.hzeport.bgs22emduty.entity.ScreenMessage;
import com.hzeport.bgs22emduty.entity.SecurityLog;
import com.hzeport.bgs22emduty.outbound.DutyScheduleSetCustomRecordRepository;
import com.hzeport.bgs22emduty.outbound.ScreenMessageRepository;
import com.hzeport.bgs22emduty.outbound.db.mapper.DutyScheduleSetCustomRecordMapper;
import com.hzeport.bgs22emduty.outbound.db.mapper.ScreenMessageMapper;
import com.hzeport.bgs22emduty.service.SecurityLogService;
import com.hzeport.bgs22emduty.common.base.BaseResult;
import com.hzeport.bgs22emduty.common.utils.IpUtils;
import com.hzeport.bgs22emduty.common.base.BaseRepositoryImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@Service
public class ScreenMessageRepositoryImpl extends BaseRepositoryImpl<ScreenMessageMapper, ScreenMessage> implements ScreenMessageRepository {

    @Resource
    private SecurityLogService securityLogService;
    @Override
    public BaseResult savels(ScreenMessageReadDTO screenDutyMessageSaveVO, HttpServletRequest request) {
        ScreenMessage screenMessage=new ScreenMessage();
        screenMessage.setHasReaded("1");
        screenMessage.setReadBy(screenDutyMessageSaveVO.getReadBy());
        this.update(screenMessage,new LambdaQueryWrapper<ScreenMessage>()
        .in(ScreenMessage::getId,screenDutyMessageSaveVO.getIds()));

        SecurityLog operateLog = new SecurityLog();
        operateLog.setCreateBy(screenDutyMessageSaveVO.getReadBy());
        operateLog.setCreateTime( LocalDateTime.now());
        operateLog.setIpAddress( IpUtils.getIpAddr(request));
        operateLog.setSDescription( JSON.toJSONString( screenDutyMessageSaveVO ) );
        operateLog.setSModule("ZBDXLS");
        operateLog.setSTitle("ZBBC");
        securityLogService.save(operateLog);

        return BaseResult.ok("保存成功");
    }
}
